package com.guigu.controller;

import com.guigu.entity.Menu;
import com.guigu.service.MenuService;
import com.guigu.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller
public class MenuController {

    @Autowired
    private MenuService menuService;

    @GetMapping("/index")
    public String index() {
        return "index";
    }

    @GetMapping("/queryMenu")
    public Result<List<Menu>> findAll() {

        List<Menu> menu= this.menuService.queryMenu();

        return new Result<>("200", "true", "成功查询菜单", menu);
    }
    @GetMapping("/addMenu")
    public String addMenu(Menu menu){
         this.menuService.addMenu(menu);
        return "ok";
    }
    @GetMapping("/updateMenu")
    public String updateMenu(Menu menu){
        this.menuService.updateMenu(menu);
        return "ok";
    }
    @GetMapping("/ByIdMenu")
    public Menu ByIdMenu(int id){
        return this.menuService.ByIdMenu(id);
    }
    @GetMapping("/deleteMenu")
    public String deleteMenu(int id){
         this.menuService.deleteMenu(id);
        return "ok";
    }
}
